package ua.cs.stu.ics.dbf;

import com.linuxense.javadbf.DBFException;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import ua.cs.stu.ics.dbf.exceptions.DBException;
import ua.cs.stu.ics.dbf.readers.DBFAbstractReader;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 * User: Evgeniy Berlog
 * Date: 12.02.11
 * Time: 22:47
 */
public class DBReaderFactory implements ApplicationContextAware {
    private List readers;
    private Map files;
    private ApplicationContext applicationContext;

    public void init() {
        for (Object bean : getReaders()) {
            DBFAbstractReader reader = (DBFAbstractReader) applicationContext.getBean((String) bean);
            try {
                reader.read((String) files.get(bean));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public List getReaders() {
        return readers;
    }

    public void setReaders(List readers) {
        this.readers = readers;
    }

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public Map getFiles() {
        return files;
    }

    public void setFiles(Map files) {
        this.files = files;
    }
}

